<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

	public function index(){
		$user = M('user');

		if($_POST['sub']){
			$map['username'] = $_POST['username'];
			$map['password'] = md5($_POST['password']);
// var_dump($map);die;
			$count = $user->where($map)->count();
			// $count = "select count(*) from et_user where username='admin' and password ='{$map['password']}'";
			echo $count;die;
			var_dump($count);

			if($count){
				$data=$user->where($map)->select();	
				var_dump($data);
			}

			if($count){
				if(md5($_POST['password']) == $data[0]['password']){
					$_SESSION['data']=$data[0];
					$this->redirect('Index/index');
				}else{
					$this->error('密码错误！');
				}
			}else{
				$this->error("用户不存在！");
			}
			
		}
		$this->display();
	}


}